package com.zr.gdms.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONObject;

import com.zr.gdms.model.Student;
import com.zr.gdms.service.StudentServiceSCM;
import com.zr.gdms.serviceimpl.StudentServiceImplSCM;

/**
 * @author  shichongming
 * @E-mail: 
 * @date 创建时间：2017年5月27日 下午5:42:40 
 * @version 1.0 
 * @parameter  
 * @since  
 * @return  
 */

public class SelectCourseControllerSCM extends HttpServlet{
			StudentServiceSCM stu=new StudentServiceImplSCM();
	//选择课题
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {	
		doPost(req, resp);
	}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
	       req.setCharacterEncoding("utf-8");
           resp.setCharacterEncoding("utf-8");	  
           HttpSession  session=req.getSession();
           int cid=Integer.parseInt(req.getParameter("cid"));
           String cstate=req.getParameter("cstate");    
           Student st=(Student)session.getAttribute("student");         
	       int sid=st.getSid(); 
	     
	       int cid1=stu.sselectCourseExistBySid(sid);	//判断自己是否选过课题       	      
	       PrintWriter pw=resp.getWriter();	   
	      
	   if(cid1>0){
		   pw.write("0");	
	   }else{		
		   boolean flag=stu.supdatecourseCstateBycid(cid);		   
		   if(flag){
			   boolean flag1=stu.sinsertscoreBySidCid(sid, cid);			
			   if(flag1){
				   pw.write("1");
			   }else{
				   pw.write("0");		   
			   }  
		   }else{
			   pw.write("0");	
		   }   
	   }  
}
}
